{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "checked-spider",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, 1)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = 5\n",
    "a,b = 0,1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "alpha-teach",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "h = (b-a)/n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "discrete-paintball",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6-element Vector{Float64}:\n",
       " 0.0\n",
       " 0.2\n",
       " 0.4\n",
       " 0.6\n",
       " 0.8\n",
       " 1.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = collect(a:h:b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "distributed-advisory",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "f (generic function with 1 method)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f(x) = log(1+x)/(1+x^2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "declared-sister",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6-element Vector{Float64}:\n",
       " 0.0\n",
       " 0.17530918922495634\n",
       " 0.2900622729493214\n",
       " 0.34559090385715857\n",
       " 0.358406502989097\n",
       " 0.34657359027997264"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = f.(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "sustained-milan",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.26853113283210395"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "T₅ = h/2*sum(y[1:end-1].+y[2:end])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "concrete-pressure",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "NIntegrateᵀ (generic function with 1 method)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function NIntegrateᵀ(y,(a,b))\n",
    "    n = length(y) - 1\n",
    "    h = (b-a)/n\n",
    "    return h/2*sum(y[1:end-1].+y[2:end]) \n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "molecular-count",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.26853113283210395"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NIntegrateᵀ(y,(0,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "mounted-lodge",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5-element Vector{Float64}:\n",
       " 0.1\n",
       " 0.3\n",
       " 0.5\n",
       " 0.7\n",
       " 0.9"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xh = 0.1:h:0.9 |> collect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "computational-navigator",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5-element Vector{Float64}:\n",
       " 0.09436651465774747\n",
       " 0.24070116006191838\n",
       " 0.3243720864865315\n",
       " 0.3561263429947452\n",
       " 0.3546154067250799"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.(xh)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia",
   "language": "julia",
   "name": "julia-1.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
